package com.os.crm.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.os.crm.mapper.TaskDetailMapper;
import com.os.crm.pojo.TaskDetail;
import com.os.util.Tools;
import com.os.util.page.PageRequest;
import com.os.util.page.PageResult;
import com.os.util.page.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class TaskDetailService {
    @Autowired
    private TaskDetailMapper taskDetailMapper;
    /**
     * 采用分页插件进行分页
     * @param pageRequest
     * @param map
     * @return
     */
    public PageResult selectByPage(PageRequest pageRequest, Map map) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<TaskDetail> taskDetailList = taskDetailMapper.selectByParam(map);
        Tools.indexOrder(taskDetailList,"index");
        PageInfo pageInfo = new PageInfo<TaskDetail>(taskDetailList);
        return PageUtils.getPageResult(pageRequest, pageInfo);
    }
    /**
     * 按ID查询数据采集任务明细
     * @param id
     * @return
     */
    public TaskDetail selectById(int id){
        return taskDetailMapper.selectById(id);
    }

    /**
     * 新增数据采集任务明细
     * @param taskDetail
     */
    public void insert(TaskDetail taskDetail){
        taskDetailMapper.insertSelective(taskDetail);
    }
    /**
     * 修改数据采集任务明细
     * @param taskDetail
     */
    public void update(TaskDetail taskDetail){
        taskDetailMapper.updateByPrimaryKeySelective(taskDetail);
    }

    /**
     * 按ID删除数据采集任务明细
     * @param id
     */
    public void deleteById(int id){
        taskDetailMapper.deleteById(id);
    }
}